﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Gestion.Ui;
using Gestion.Domain.Entities;

namespace Gestion.Web.Empresa.Riesgo
{
    public partial class ListRiesgo : BasePage
    {
        #region Properties

        #endregion

        #region Control Events

        protected void Page_Load(object sender, EventArgs e)
        {
            GrdRiesgos.DataSource = ServiceManager.RiesgoService.FindAll();
            GrdRiesgos.DataBind();
        }

        protected void GrdRiesgos_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            Int64 idRiesgo = Convert.ToInt64(GrdRiesgos.DataKeys[Convert.ToInt32(e.CommandArgument)].Value);
            RiesgoEntity riesgo = ServiceManager.RiesgoService.GetById(idRiesgo);

            if (e.CommandName == "VerDetalles")
            {
                //Falta Implementar
                Response.Redirect(ServiceManager.WebformNavigation.RiesgoEdit(idRiesgo));
            }
            if (e.CommandName == "Editar")
            {
                Response.Redirect(ServiceManager.WebformNavigation.RiesgoEdit(idRiesgo));
            }
            if (e.CommandName == "Eliminar")
            {
                DoDelete(riesgo);
            }
        }

        protected void BtnAddRiesgo_Click(object sender, EventArgs e)
        {
            Response.Redirect(ServiceManager.WebformNavigation.RiesgoAdd());
        }

        #endregion

        #region Service-based Actions

        private void DoDelete(RiesgoEntity riesgo)
        {
            if (!ServiceManager.RiesgoService.IsHasDetailsRisks(riesgo))
            {
                ServiceManager.RiesgoService.DeleteById(riesgo.Id);
            }
            else
            { 
                
            }
        }

        #endregion      
    }
}
